package com.darren.archive.service.impl;

import com.darren.archive.dao.SysRoleDao;
import com.darren.archive.entity.SysRole;
import com.darren.archive.repository.SysRoleRepository;
import com.darren.archive.service.SysRoleService;
import com.darren.framework.service.impl.GenericServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <pre>
 * *********************************************
 * Copyright DARREN
 * All rights reserved.
 * Description: TODO(description)
 * HISTORY:
 * *********************************************
 *  Version		Date		Author	   		Desc
 *   v1.0       2019-12-07  Darren Zhou    Create
 *
 * *********************************************
 * </pre>
 */

@Service
@Transactional(rollbackFor = Exception.class)//默认该类的所有方法都开启事务，遇到Exception就回滚
public class SysRoleServiceImpl extends GenericServiceImpl<SysRole, Long> implements SysRoleService {

    @Resource
    private SysRoleDao sysRoleDao;

    @Autowired
    private SysRoleRepository sysRoleRepository;


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)//不开启事务的支持
    public Page<SysRole> findByNameLike(String name, Pageable pageable) {
        return sysRoleRepository.findByNameLike(name,pageable);
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)//不开启事务的支持
    public Page<SysRole> findAll(Pageable pageable) {
        return sysRoleRepository.findAll(pageable);
    }

    @Override
    public SysRole saveEnable(SysRole record) {
        SysRole sysRole = sysRoleDao.findById(record.getId());
        sysRole.setEnable(record.isEnable());
        return sysRoleDao.save(sysRole);
    }

}
